import os
import re
import shlex
import subprocess
from subprocess import PIPE

cmd = shlex.split("ipconfig")
p = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
output = stdout.decode("gbk")
ips = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{2,3}|\d{1,3}\.\d{1,3}\.\d{1,3}\.[2-9]", output)
ips = "\n".join(ips)
with open("ip_address.txt", "w") as f:
    f.write(ips)
